/**
 * @file codeforces/1691/c/main
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/6/17 22:48:50
 **/

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = INF;
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int ones = 0, p1_first = n, p1_last = -1;
    for (int p = 0; p < n; ++p) {
      if (s[p] != '1') continue;
      ones += 1;
      if (p1_first == n) p1_first = p;
      p1_last = p;
    }
    int add = 0;
    if (ones > 0 && (n - 1 - p1_last) <= k) {
      k -= (n - 1 - p1_last);
      add += 1;
      ones -= 1;
    }
    if (ones > 0 && p1_first <= k) {
      k -= p1_first;
      add += 10;
      ones -= 1;
    }
    cout << 11 * ones + add << '\n';
  };
  return 0;
}
